﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace WPFCustomControlLibrary
{
    public class ProgressBar : UserControl
    {
        public ProgressBar()
        {
            this.InitializeComponent();
            this.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            this.VerticalAlignment = System.Windows.VerticalAlignment.Center;
        }

        private void InitializeComponent()
        {
            Grid grid = new Grid();
            this.Content = grid;

            List<Path> pathList = new List<Path>();

            for (int i = 0; i < 12; i++)
            {
                Path path = new Path();
                path.Data = Geometry.Parse("M 0,0 L -1,0 L -1,-7 L 1,-7 L 1,0 Z");
                path.Fill = new SolidColorBrush(Colors.White);

                TransformGroup tg = new TransformGroup();

                TranslateTransform tt = new TranslateTransform();
                tt.Y = -7;

                RotateTransform rt = new RotateTransform();
                rt.Angle = i * 30;

                tg.Children.Add(tt);
                tg.Children.Add(rt);

                path.RenderTransform = tg;

                pathList.Add(path);
                grid.Children.Add(path);

                DoubleAnimation da = new DoubleAnimation();
                da.From = 1.0;
                da.To = 0.2;
                da.Duration = new System.Windows.Duration(TimeSpan.FromSeconds(1));
                da.BeginTime = TimeSpan.FromMilliseconds(i * 1000 / 12);
                da.RepeatBehavior = RepeatBehavior.Forever;

                path.BeginAnimation(Path.OpacityProperty, da);
            }

        }
    }
}
